package es.onlysolutions.gs.comm.filter;

import es.onlysolutions.arq.core.auth.UserManager;
import es.onlysolutions.gs.comm.entity.User;
import es.onlysolutions.gs.comm.utils.UserSettings;
import org.hibernate.criterion.Restrictions;

/**
 * Filter by the user in session for the videos.
 */
public class UserVideoFilter extends VideoFilter
{
    public UserVideoFilter()
    {
        //always filter for user in session.
        UserSettings userSettings = (UserSettings) UserManager.instance().getUser();

        if( userSettings != null ) //If user is null, we are not under session, so list all.
        {
            User userToList = userSettings.getUser();
            addRestriction(Restrictions.eq("user", userToList));
        }

        addAscOrder("title");
    }
}
